<?php

/**
 * 文件注释
 *
 * Author: Liam
 * Datetime: 03/22/18 10:45 AM
 */

namespace ApiBundle\Controller;

use BaseBundle\Controller\BaseController;
use Symfony\Component\HttpFoundation\Request;

class AuthController extends BaseController
{
    /*
    * 登录
    */
    public function loginAction(Request $request)
    {
        $email = $request->get('email');
        $password = sha1(md5($request->get("password")));

        // TODO: 判断手机号是否注册
        $conn = $this->get("database_connection");
        $user = $conn->fetchAssoc("SELECT * FROM admin WHERE username = '" . $email . "'");
        if ($email != $user['username'] and $password != $user['password']) {
            return $this->jsonResponse('用户名或密码错误', 1);
        }

        $this->get("session")->set("admin_name", $email);

        return $this->jsonResponse("操作成功", 0);
    }
}

